<?php
    $this->layout('base.phtml', [
        'title' => _('Feeds'),
        'canonical' => url_full('feeds'),
        'current_tab' => 'feeds',
        'current_page' => 'feeds',
        'back_options' => [
            'reset' => true,
        ],
    ]);
?>

<div class="section">
    <div class="section__title">
        <h1><?= _('Feeds') ?></h1>
    </div>

    <div class="section__intro">
        <p>
            <?= _('All the feeds that you follow are listed here.') ?>
        </p>

        <p>
            <?= _f('<a href="%s">Discover collections feeds</a>', url('discovery')) ?>
        </p>
    </div>

    <section class="group">
        <div class="cards">
            <div class="card">
                <button
                    class="card__button"
                    data-controller="modal-opener"
                    data-action="modal-opener#fetch"
                    data-modal-opener-href-value="<?= url('new feed', ['from' => url('feeds')]) ?>"
                    aria-haspopup="dialog"
                    aria-controls="modal"
                >
                    <?= icon('plus') ?><br />
                    <?= _('Add a feed') ?>
                </button>
            </div>

            <?php $collections = $groups_to_collections[null] ?? []; ?>

            <?php foreach ($collections as $collection): ?>
                <?= $this->include('collections/_collection.phtml', [
                    'collection' => $collection,
                    'display_by' => true,
                    'display_number_links' => true,
                    'display_visibility' => false,
                ]) ?>
            <?php endforeach; ?>

            <?php for ($i = 0; $i < (3 - ((count($collections) + 1) % 3)); $i++): ?>
                <div class="card card--shadow no-mobile"></div>
            <?php endfor; ?>
        </div>
    </section>

    <?php foreach ($groups as $group): ?>
        <?php if (isset($groups_to_collections[$group->id])): ?>
            <?= $this->include('groups/_group.phtml', [
                'group' => $group,
                'collections' => $groups_to_collections[$group->id],
                'display_by' => true,
                'display_number_links' => true,
                'display_visibility' => false,
                'from' => url('feeds'),
            ]) ?>
        <?php endif; ?>
    <?php endforeach; ?>
</div>
